# encoding: utf-8
import pymysql
#建立连接
def connDB():
    conn = pymysql.connect(host='localhost', user='root', passwd='root', db='travel', charset='utf8')
    cur = conn.cursor()
    return (conn,cur)

#更新语句，可执行update,insert语句
def exeUpdate(cur,sql):
    sta=cur.execute(sql);
    return(sta)

#删除语句，可批量删除
def exeDelete(cur,IDs):
    for eachID in IDs.split(' '):
        sta=cur.execute('delete from relationTriple where tID =%d'% int(eachID));
    return (sta)

#查询语句
def exeQuery(cur,sql):
    cur.execute(sql)
    return (cur)

#关闭所有连接
def connClose(conn,cur):
    cur.close()
    conn.close()

#调用连接数据库的函数
conn,cur=connDB()

exeQuery(cur,"select * from city")
for row in cur:
    print('%s\t%s\t%s\t%s' % row)
